<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./art-template.js"></script>
</head>

<body>

    <div></div>

    <!-- 定义一块模板(一块html标签) -->
    <script id="model1" type="text/html">
        <p>这是内容</p>
        <!-- 在模板中,使用双大括号{{属性名}}来显示对象内属性值 -->
        <p>{{con}}</p>
        <p>{{name}}</p>
        <ul>
            {{each arr as item}}
            <li>{{item}}</li>
            {{/each}}
        </ul>
        <ul>
            {{each data as item}}
            <li>
                <p>{{item.name}}</p>
                {{if item.sex === true}}
                    <p>女</p>
                {{else}}
                    <p>男</p>
                {{/if}}
            </li>
            {{/each}}
        </ul>
    </script>

    <script>
        // 模板引擎
        // 将  1.一块html标签 与 2.js数据 相  3.结合(先将属性填写至模板,然后结合),
        // 4.渲染页面

        // 得到的js数据
        var obj = {
            con: "这是一段在js对象内的内容",
            name: "lili",
            arr: ["内容1", "内容2", "内容3"],
            data: [{ 
                name: "data1", 
                sex: true 
            }, { 
                name: "data2", 
                sex: false 
            }, { 
                name: "data2", 
                sex: true 
            }]
        }
        var data = template("model1", obj);
        console.log(data);
        document.querySelector("div").innerHTML = data;
    </script>
</body>

</html>